<template>
  <div class="decode-form">
    <el-form
        :model="mainData"
        :rules="rules"
        ref="ruleForm"
    >
      <div class="form-row">
        <div class="form-item" v-for="mapAttr in mapAttrs" :key="mapAttr.KeyOfEn"
             v-if="mapAttr.UIVisible === 1"
             :style="calcFormItemWidth(mapAttr,'outer')">
          <div class="form-item-label" :style="calcFormItemWidth(mapAttr,'label')">
            {{ mapAttr.Name }}
          </div>
          <div class="form-item-content" :style="calcFormItemWidth(mapAttr,'content')">
            <el-form-item
                v-if="mapAttr.DataType == 'Input'"
                :prop="mapAttr.KeyOfEn"
                :disabled="mapAttr.UIIsEnable == 0"
            >
              <!--只读的富文本显示-->
              <template v-if="mapAttr.type == 'div'">
                <div v-html="mainData[mapAttr.KeyOfEn]"></div>
              </template>
              <!--大文本显示-->
              <template v-else-if="mapAttr.type == 'textarea'">
                <el-input
                    type="textarea"
                    v-model="mainData[mapAttr.KeyOfEn]"
                    :disabled="mapAttr.UIIsEnable == 0 ? true : false"
                ></el-input>
              </template>
              <!--富文本编辑器-->
              <template v-else-if="mapAttr.type == 'richText'"></template>
              <!--自动补全-->
              <template v-else-if="mapAttr.type == 'tbFullCtrl'">
                <el-autocomplete
                    v-model="mainData[mapAttr.KeyOfEn]"
                    value-key="Name"
                    :fetch-suggestions="
                (queryString, cb) => {
                  querySearchAsync(queryString, cb, mapAttr);
                }
              "
                    placeholder="请输入内容"
                    @select="
                (item) => {
                  handleSelect(item, mapAttr);
                }
              "
                ></el-autocomplete>
              </template>
              <!--POP弹出框的处理-->
              <template
                  v-else-if="
              mapAttr.type == 'PopBranchesAndLeaf' ||
              mapAttr.type == 'PopBranches' ||
              mapAttr.type == 'PopTableSearch'
            "
              >
                <Popover
                    :mapExts="mapAttr.MapExts"
                    :popModel="mapAttr.type"
                ></Popover>
              </template>
              <template v-else-if="mapAttr.type == 'PopSelfUrl'"></template>
              <template
                  v-else-if="
              mapAttr.type == 'PopBindSFTable' ||
              mapAttr.type == 'PopBindEnum' ||
              mapAttr.type == 'PopTableList'
            "
              >
                <el-select
                    :multiple="mapAttr.selectType"
                    v-model="mainData[mapAttr.KeyOfEn]"
                >
                  <el-option
                      v-for="item in mapAttr.Options"
                      :label="item.Name"
                      :value="item.No"
                      :key="item.No"
                  ></el-option>
                </el-select>
              </template>
              <template v-else-if="mapAttr.type == 'PopGroupList'">
                <el-select
                    :multiple="mapAttr.selectType"
                    v-model="mainData[mapAttr.KeyOfEn]"
                    placeholder="请选择"
                >
                  <el-option-group
                      v-for="group in mapAttr.Options"
                      :key="group.No"
                  >
                    <el-option
                        v-for="item in group.options"
                        :label="item.Name"
                        :key="item.No"
                        :value="item.No"
                    >
                    </el-option>
                  </el-option-group>
                </el-select>
              </template>
              <!--小范围多选-->
              <template v-else-if="mapAttr.type == 'checkBoxs'">
                <el-select multiple v-model="mainData[mapAttr.KeyOfEn]">
                  <el-option
                      v-for="item in mapAttr.Options"
                      :label="item.Name"
                      :value="item.No"
                      :key="item.No"
                  ></el-option>
                </el-select>
              </template>
              <!--小范围单选-->
              <template v-else-if="mapAttr.type == 'radio'">
                <el-select v-model="mainData[mapAttr.KeyOfEn]">
                  <el-option
                      v-for="item in mapAttr.Options"
                      :label="item.Name"
                      :value="item.No"
                      :key="item.No"
                  ></el-option>
                </el-select>
              </template>
              <!--搜索多选-->
              <template v-else-if="mapAttr.type == 'ChoiceSearch'">
                <el-select
                    v-model="mainData[mapAttr.KeyOfEn]"
                    multiple
                    filterable
                    remote
                    reserve-keyword
                    placeholder="请输入关键词"
                    :remote-method="
                (query) => {
                  remoteMethod(query, mapAttr, idx);
                }
              "
                    :loading="mapAttr.loading"
                    @change="SaveFrmEleDB($event, mapAttr)"
                >
                  <el-option
                      v-for="item in mapAttr.Options"
                      :key="item.No"
                      :label="item.Name"
                      :value="item.No"
                  >
                  </el-option>
                </el-select>
              </template>
              <!--高级快速录入-->
              <template v-else-if="mapAttr.type == 'InputSearch'">
                <el-select
                    v-model="mainData[mapAttr.KeyOfEn]"
                    multiple
                    filterable
                    allow-create
                    default-first-option
                    remote
                    reserve-keyword
                    :remote-method="
                (query) => {
                  remoteMethod(query, mapAttr, idx);
                }
              "
                    :loading="mapAttr.loading"
                    :placeholder="'请选择' + mapAttr.Name"
                    @change="SaveFrmEleDB($event, mapAttr)"
                >
                  <el-option
                      v-for="item in mapAttr.Options"
                      :key="item.No"
                      :label="item.Name"
                      :value="item.No"
                  >
                  </el-option>
                </el-select>
              </template>
              <!--文本-->
              <template v-else>
                <el-input
                    v-model="mainData[mapAttr.KeyOfEn]"
                    @blur="BindFunc(mapAttr)"
                    :disabled="mapAttr.UIIsEnable == 0 ? true : false"
                ></el-input>
              </template>
            </el-form-item>
            <!--DDL下拉框-->
            <el-form-item
                v-else-if="mapAttr.DataType == 'DDL'"
                :disabled="mapAttr.UIIsEnable == 0"
            >
              <el-select
                  v-model="mainData[mapAttr.KeyOfEn]"
                  :placeholder="'请选择' + mapAttr.Name"
                  :disabled="mapAttr.UIIsEnable == 0 ? true : false"
                  @change="SelectChange($event, mapAttr, true, true)"
              >
                <el-option
                    v-for="op in mapAttr.Options"
                    :label="op.Name"
                    :value="op.No"
                    :key="op.No"
                ></el-option>
              </el-select>
            </el-form-item>
            <!--枚举-->
            <el-form-item
                v-else-if="mapAttr.DataType == 'Radio'"
                :disabled="mapAttr.UIIsEnable == 0"
            >
              <el-radio-group
                  v-model="mainData[mapAttr.KeyOfEn]"
                  :disabled="mapAttr.UIIsEnable == 0"
              >
                <el-radio
                    v-for="ra in mapAttr.Options"
                    :label="ra.No"
                    :key="ra.No"
                >{{ ra.Name }}
                </el-radio
                >
              </el-radio-group>
            </el-form-item>
            <!--复选框-->
            <el-form-item
                v-else-if="
            mapAttr.DataType == 'CheckBox' && mapAttr.type == 'checkbox'
          "
                :disabled="mapAttr.UIIsEnable == 0"
            >
              <el-switch
                  v-model="mainData[mapAttr.KeyOfEn]"
                  :disabled="mapAttr.UIIsEnable == 0 ? true : false"
                  @change="CheckBoxChange(mapAttr)"
              ></el-switch>
            </el-form-item>
            <el-form-item
                v-else-if="
            mapAttr.DataType == 'CheckBox' && mapAttr.type == 'checkboxs'
          "
                :disabled="mapAttr.UIIsEnable == 0"
            >
              <el-checkbox-group
                  v-model="mainData[mapAttr.KeyOfEn]"
                  :disabled="mapAttr.UIIsEnable == 0 ? true : false"
              >
                <el-checkbox
                    v-for="ch in mapAttr.Options"
                    :label="ch.No"
                    :key="ch.Name"
                >{{ ch.Name }}
                </el-checkbox
                >
              </el-checkbox-group>
            </el-form-item>
            <!--日期时间-->
            <el-form-item
                v-else-if="mapAttr.DataType == 'Date'"
                :disabled="mapAttr.UIIsEnable == 0"
            >
              <template v-if="mapAttr.type == 'datetime'">
                <el-date-picker
                    v-model="mainData[mapAttr.KeyOfEn]"
                    type="datetime"
                    :format="mapAttr.dateFmt"
                    :value-format="mapAttr.dateFmt"
                    :placeholder="'选择' + mapAttr.Name"
                    @focus="DateFocus(mapAttr)"
                    :picker-options="pickerOptions"
                    @change="DateChange(mapAttr)"
                >
                </el-date-picker>
              </template>
              <template v-else-if="mapAttr.type == 'time'">
                <el-time-select
                    v-model="mainData[mapAttr.KeyOfEn]"
                    :format="mapAttr.dateFmt"
                    :value-format="mapAttr.dateFmt"
                    placeholder="选择时间"
                    size="small"
                    @focus="DateFocus(mapAttr)"
                    :picker-options="pickerOptions"
                    @change="DateChange(mapAttr)"
                >
                </el-time-select>
              </template>
              <template v-else>
                <el-date-picker
                    v-model="mainData[mapAttr.KeyOfEn]"
                    type="date"
                    :format="mapAttr.dateFmt"
                    :value-format="mapAttr.dateFmt"
                    :placeholder="'选择' + mapAttr.Name"
                    size="small"
                    @focus="DateFocus(mapAttr)"
                    :picker-options="pickerOptions"
                    @change="DateChange(mapAttr)"
                >
                </el-date-picker>
              </template>
            </el-form-item>
            <el-form-item
                v-else-if="mapAttr.DataType == 'Number'"
                :disabled="mapAttr.UIIsEnable == 0"
            >
              <el-input-number
                  v-model="mainData[mapAttr.KeyOfEn]"
                  :step="1"
                  :disabled="mapAttr.UIIsEnable == 0"
                  @blur="BindFunc(mapAttr)"
                  @change="ChageOtherValue(mapAttr)"
              ></el-input-number>
            </el-form-item>
            <el-form-item
                v-else-if="mapAttr.DataType == 'Float'"
                :disabled="mapAttr.UIIsEnable == 0"
            >
              <el-input-number
                  v-model="mainData[mapAttr.KeyOfEn]"
                  :precision="mapAttr.precision"
                  :step="0.1"
                  :disabled="mapAttr.UIIsEnable == 0 ? true : false"
                  @change="ChageOtherValue(mapAttr)"
              ></el-input-number>
            </el-form-item>
            <el-form-item
                v-else-if="mapAttr.DataType == 'Money'"
                :disabled="mapAttr.UIIsEnable == 0"
            >
              <el-input-number
                  v-model="mainData[mapAttr.KeyOfEn]"
                  :precision="mapAttr.precision"
                  :step="0.1"
                  :disabled="mapAttr.UIIsEnable == 0 ? true : false"
                  @change="ChageOtherValue(mapAttr)"
              ></el-input-number>
            </el-form-item>
          </div>
        </div>
      </div>
    </el-form>
  </div>
</template>

<script>
import {getInputValue} from "../../api/js/Money.js";
import * as formEnd from "@/api/js/MapAttrForm.js";
import {
  sendThis,
  GetDataTableByDB,
  FullIt,
  DealExp,
  ReqDays,
} from "@/api/MapExt.js";
import Popover from "../ccform/Pop/Popover.vue";
import {
  FloatInputCheck,
  testExpression,
  calculator,
  CoverMoneyToChinese,
} from "@/api/tools.js";
import Vue from "vue";

Vue.prototype.$formEnd = formEnd;
export default {
  name: "MapAttrForm",
  props: {
    mapAttrs: {
      type: Array,
      default: () => [],
    },
    formGrid: {
      type: [String, Number],
      default: 4
    },
    mainData: {},
    frmData: {},
    rules: {},
  },
  components: {
    Popover,
  },
  data() {
    return {
      func: "", //(function(){if(_this.webUser.No=='admin'){return 10}else{return 11}})() 执行函数
      webUser: {},
      params: {},
      //mapAttrs:[],
      currMapAttr: {},
    };
  },
  mounted() {
    // 发送this 到 js 文件里
    sendThis(this);

  },
  created() {
    this.webUser = this.$store.getters.getWebUser;
    this.params = this.$store.getters.getData;
    //根据mapExt
  },

  methods: {
    calcFormItemWidth(item, type) {
      const {ColSpan, RowSpan} = item
      let LabelColSpan = item.LabelColSpan;
      if(LabelColSpan==undefined || LabelColSpan==null)
        LabelColSpan = item.TextColSpan;
      if (type === 'outer') {
        return {
          width: `${(ColSpan + LabelColSpan) / this.formGrid * 100 + '%'}`
        }
      }
      if (type === 'label') {
        let percent = (LabelColSpan / (ColSpan + LabelColSpan)) * 66
        if (percent < 16.6) {
          percent = this.formGrid === 6 ? percent : 16.6
        }
        return {
          width: `${percent}%`,
        }
      }
      if (type === "content") {
        return {
          width: `${(ColSpan / (ColSpan + LabelColSpan)) * 133 + '%'}`,
          height: `${RowSpan * 100 + '%'}`
        }
      }
      return {}
    },
    /**
     * 搜索多选，快速录入
     * @param query
     * @param mapAttr
     * @param idx
     */
    remoteMethod(query, mapAttr, idx) {
      let _this = this;
      if (query !== "") {
        this.loading = true;
        //setTimeout(() => {
        this.loading = false;
        let mapExt = mapAttr.MapExts[0];
        let dt = GetDataTableByDB(
            mapExt.Doc,
            mapExt.DBType,
            mapExt.FK_DBSrc,
            query
        );
        mapAttr.Options = [];
        dt.forEach(function (item) {
          mapAttr.Options.push({
            No: item.No,
            Name: item.Name,
          });
        });

        _this.$set(_this.mapAttrs[idx], "Options", mapAttr.Options);
        _this.$forceUpdate();
        //}, 200);
      } else {
        _this.$set(_this.mapAttrs[idx], "Options", []);
      }
    },
    querySearchAsync(queryString, cb, mapAttr) {
      let mapExt = mapAttr.MapExts[0];
      let data = GetDataTableByDB(
          mapExt.Tag4,
          mapExt.DBType,
          mapExt.FK_DBSrc,
          queryString
      );

      clearTimeout(this.timeout);
      this.timeout = setTimeout(() => {
        cb(data);
      }, 3000 * Math.random());
    },
    SaveFrmEleDB(item, mapAttr) {
      let pkVal = this.params.WorkID;
      pkVal = pkVal == undefined || pkVal == 0 ? this.params.OID : pkVal;
      //删除
      let ens = new this.Entities("BP.Sys.FrmEleDBs");
      ens.Delete(
          "FK_MapData",
          mapAttr.FK_MapData,
          "EleID",
          mapAttr.KeyOfEn,
          "RefPKVal",
          pkVal
      );

      //保存
      item.forEach((obj) => {
        let frmEleDB = new this.Entity("BP.Sys.FrmEleDB");
        let selectItem = this.$.grep(mapAttr.Options, function (option) {
          return option.No == obj;
        })[0];
        frmEleDB.MyPK = mapAttr.KeyOfEn + "_" + pkVal + "_" + obj;
        frmEleDB.FK_MapData = mapAttr.FK_MapData;
        frmEleDB.EleID = mapAttr.KeyOfEn;
        frmEleDB.RefPKVal = pkVal;
        frmEleDB.Tag1 = obj;
        frmEleDB.Tag2 = selectItem.Name;
        frmEleDB.Insert();
      });
    },

    handleSelect(item, mapAttr) {
      this.mainData[mapAttr.KeyOfEn] = item.No;
      let mapExt = mapAttr.MapExts[0];
      //填充其他控件
      FullIt(item.No, mapExt, mapAttr);
    },
    /**
     * 执行
     * @param mapAttr
     * @constructor
     */
    BindFunc(mapAttr) {
      let mapExts = mapAttr.MapExts;
      if (mapExts == undefined || mapExts.length == 0) return;
      mapExts.forEach((mapExt) => {
        if (mapExt.ExtType == "BindFunction") {
          let doc = mapExt.Doc;
          doc = doc.replace(/~/g, "'");
          doc = DealExp(doc);
          this.func = "(" + doc + ")()";
          eval(this.func);
        }
      });
    },
    /**
     * 数值型字段值发生变化的时候
     * @param mapAttr
     * @constructor
     */
    ChageOtherValue(mapAttr) {
      let mapExts = mapAttr.MapExts;
      if (mapExts == undefined || mapExts.length == 0) return;
      mapExts.forEach((mapExt) => {
        if (
            (mapExt.ExtType == "RMBDaXie" && mapExt.Doc != undefined) ||
            mapExt.Doc != ""
        )
          this.mainData[mapExt.Doc] = CoverMoneyToChinese(
              this.mainData[mapAttr.KeyOfEn]
          );
        if (
            (mapExt.ExtType == "AutoFull" && mapExt.Doc != undefined) ||
            mapExt.Doc != ""
        ) {
          let doc = mapExt.Doc;
          this.mainData[mapExt.AttrOfOper] = eval(DealExp(doc, this));
        }
      });
    },
    /**
     * 时间字段获得焦点的时候
     */
    DateFocus: function (mapAttr) {
      this.currMapAttr = mapAttr;
    },
    DateChange: function (mapAttr) {
      // let val = this.mainData[mapAttr.KeyOfEn];
      //把Date转换成特定的日期格式
      let mapExts = mapAttr.MapExts;
      if (mapExts == undefined || mapExts.length == 0) return;
      let _this = this;
      mapExts.forEach((mapExt) => {
        if (mapExt.ExtType == "BindFunction") {
          let doc = mapExt.Doc;
          doc = doc.replace(/~/g, "'");
          doc = DealExp(doc);
          this.func = "(" + doc + ")()";
          eval(this.func);
        }

        if (mapExt.ExtType == "ReqDays") {
          _this.mainData[mapExt.AttrOfOper] = ReqDays(
              mapExt,
              _this.mainData,
              _this
          );
        }
      });
    },

    /**
     * 布尔类型的值发生变化
     * @param mapAttr
     * @constructor
     */
    CheckBoxChange(mapAttr) {
      this.BindFunc(mapAttr);
      if (mapAttr.IsEnableJs == true) {
        //设置联动
      }
    },

    /**
     *下拉框选择触发的事件
     * @param mapAttr
     * @constructor
     */
    SelectChange(item, mapAttr, isBindFunc, isEnableJS) {
      let mapExts = mapAttr.MapExts;
      if (mapExts == undefined || mapExts.length == 0) return;
      let _this = this;
      let selectVal = this.mainData[mapAttr.KeyOfEn];
      if (
          mapAttr.BindKeyType != undefined &&
          mapAttr.BindKeyType == 1 &&
          item != null
      )
        this.mainData[mapAttr.KeyOfEn + "T"] = item.Name;
      if (item == null) this.mainData[mapAttr.KeyOfEn + "T"] = "";
      //下拉框的处理顺序 级联，填充，绑定的chang事件（配置的时候按照顺序设置）
      mapExts.forEach((mapExt) => {
        if (mapExt.ExtType == "ActiveDDL") {
          //级联
          let childKeyOfEn = mapExt.AttrsOfActive; //级联下一级的元素
          let idxOfChildKey = 0;
          _this.$.each(_this.mapAttrs, function (idx, mapAttr) {
            if (mapAttr.KeyOfEn == childKeyOfEn) {
              idxOfChildKey = idx;
              return false;
            }
          });
          if (selectVal == "" || selectVal == "all") {
            _this.$set(_this.mapAttrs[idxOfChildKey], "Options", []);
            _this.mainData[childKeyOfEn] = "";
            _this.SelectChange(
                null,
                _this.mapAttrs[idxOfChildKey],
                false,
                true
            );
            _this.$forceUpdate();
            return true;
          }
          let dataObj = GetDataTableByDB(
              mapExt.Doc,
              mapExt.DBType,
              mapExt.FK_DBSrc,
              selectVal
          );
          if (dataObj == null || dataObj.length == 0) {
            _this.$set(_this.mapAttrs[idxOfChildKey], "Options", []);
            _this.mainData[childKeyOfEn] = "";
            _this.SelectChange(
                null,
                _this.mapAttrs[idxOfChildKey],
                false,
                true
            );
            _this.$forceUpdate();
            return true;
          }
          _this.$set(_this.mapAttrs[idxOfChildKey], "Options", dataObj);
          _this.$forceUpdate();
          let isHave = false;
          let itemdata = [];
          dataObj.forEach((item) => {
            if (item.No == _this.mainData[childKeyOfEn]) {
              isHave = true;
              itemdata = item;
              return false;
            }
          });
          if (isHave == false) _this.mainData[childKeyOfEn] = "";
          _this.SelectChange(
              itemdata,
              _this.mapAttrs[idxOfChildKey],
              false,
              true
          );
          return true;
        }
        //填充
        let DDLFull = _this.GetPara(mapAttr.AtPara, "IsFullData");
        if (
            DDLFull != undefined &&
            DDLFull != "" &&
            DDLFull == "1" &&
            mapExt.MyPK.indexOf("DDLFullCtrl") != -1
        ) {
          if (mapAttr.UIIsEnable == 0) return true;
          this.FullIt(selectVal, mapExt);
        }
        //绑定函数
        if (mapExt.ExtType == "BindFunction" && isBindFunc == true) {
          let doc = mapExt.Doc;
          doc = doc.replace(/~/g, "'");

          doc = DealExp(doc, _this);
          this.func = "(" + doc + ")()";
          eval(this.func);
        }
      });
      if (mapAttr.IsEnableJs == true && isEnableJS == true) {
        //设置联动
      }
    },
    //子组件校验，传递到父组件
    validateForm() {
      let flag = null;
      this.$refs["ruleForm"].validate((valid) => {
        if (valid) {
          flag = true;
        } else {
          flag = false;
        }
      });
      return flag;
    },

    inputMoney(el, name) {
      this.mainData[name] = getInputValue(el);
    },
    changeInputVal(mapAttr) {
      let keyOfEn = mapAttr.KeyOfEn;
      let defVal = mapAttr.DefVal;
      let bit = 2;
      if (defVal != null && defVal != undefined && defVal != "")
        bit = defVal.substring(defVal.lastIndexOf(".") + 1).length;
      this.mainData[keyOfEn] = FloatInputCheck(this.mainData[keyOfEn], bit);
      this.MapExtsForNumber(mapAttr);
    },
    getValue(mapAttr) {
      if (mapAttr.IsHaveMapExt == false) return;
      this.MapExtsForNumber(mapAttr);
    },
    OpenDialog(dtm) {
      //函数 @功能待定
      if (parseInt(dtm.RefMethodType) == 0) {
        //需要区分是否有参数
        //其他的是弹出框
        //}else{
      }
    },

    FullIt(selectVal, mapExt) {
      let mapExtFull;
      //判断你是不是填充其他控件
      if (mapExt.MyPK.indexOf("FullData") == -1) {
        mapExtFull = new this.Entity("BP.Sys.MapExt");
        mapExtFull.SetPKVal(mapExt.MyPK + "_FullData");
        if (mapExtFull.RetrieveFromDBSources() == 0) return;
      } else {
        mapExtFull = new this.Entity("BP.Sys.MapExt", mapExt);
        mapExtFull.MyPK = mapExt.MyPK;
      }
      //填充主表
      this.FullCtrl(selectVal, mapExt);
    },
    FullCtrl(selectVal, mapExt) {
      let dbSrc = mapExt.Doc;
      if (dbSrc == null || dbSrc == "") {
        return;
      }
      let dataObj = this.GenerDB(dbSrc, selectVal, mapExt.DBType);
      if (this.$.isEmptyObject(dataObj)) return;
      dataObj = dataObj[0]; //获得这一行数据.
      for (var key in dataObj) {
        this.$parent.mainData[key] = dataObj[key];
      }
    },

    AfterBindEn_DealMapExt() {
    },
    MapExtsForNumber(mapAttr) {
      let mapExts = mapAttr.mapExts;
      mapExts.forEach((mapExt) => {
        //自动计算
        if (
            mapExt.ExtType == "AutoFull" &&
            mapExt.Doc != null &&
            mapExt.Doc != ""
        ) {
          //自动计算
          if (testExpression(mapExt.Doc) == false) {
            this.$message.warning(
                "MyPk: " + mapExt.MyPK + ", 表达式: '" + mapExt.Doc + "'格式错误"
            );
            return true;
          }
          this.mainData[mapAttr.KeyOfEn] = calculator(
              mapExt.Doc,
              this.mainData
          );
          return true;
        }
        //计算两个时间的天数
        if (mapExt.ExtType == "ReqDays") {
          if (this.mainData[mapAttr.KeyOfEn] != 0) {
            this.mainData[mapAttr.KeyOfEn] = ReqDays(
                mapExt,
                this.mainData,
                this
            );
          }
        }
        //金额小写转大写
        if (
            mapExt.ExtType == "RMBDaXie" &&
            mapExt.Doc != null &&
            mapExt.Doc != ""
        ) {
          //转大写
          this.mainData[mapExt.Doc] = CoverMoneyToChinese(
              this.mainData[mapAttr.KeyOfEn]
          );
          return true;
        }
      });
    },
    ReqDays(mapExt, keyOfEn) {
      let startDt = mapExt.Tag1; //开始日期
      let endDt = mapExt.Tag2; //结束日期
      let type = mapExt.Tag3; //是否包含节假日 0包含，1不包含
      let dateSpan;
      startDt = Date.parse(this.mainData[startDt]);
      endDt = Date.parse(this.mainData[endDt]);
      dateSpan = endDt - startDt;
      if (Object.is(dateSpan, NaN)) {
        this.mainData[keyOfEn] = "";
        return;
      }

      if (dateSpan < 0) {
        this.$message.warning("结束时间不能小于开始时间");
        return true;
      }
      dateSpan = Math.abs(dateSpan);
      dateSpan = Math.floor(dateSpan / (24 * 3600 * 1000));
      if (type == 0) {
        //包含节假日
        var holidayEn = new this.Entity("BP.Sys.GloVar");
        holidayEn.No = "Holiday";
        if (holidayEn.RetrieveFromDBSources() == 1) {
          var holidays = holidayEn.Val.split(",");
          dateSpan = dateSpan - (holidays.length - 1);
          //检查计算的天数
          if (dateSpan <= 0) {
            this.$message.warning("请假时间内均为节假日");
            dateSpan = "";
          }
        }
      }
      this.mainData[keyOfEn] = dateSpan;
    },
  },

  computed: {
    pickerOptions() {
      // 日期设置对象
      let _this = this;
      return {
        disabledDate(time) {
          let mapExts = _this.currMapAttr.MapExts;
          if (mapExts == undefined || mapExts.length == 0) return false;
          const timestamp = time.getTime();
          let isTrue = true;
          mapExts.forEach((mapExt) => {
            if (mapExt.ExtType == "DataFieldInputRole") {
              if (mapExt.Tag1 == 1) {
                isTrue = timestamp < Date.now() - 24 * 60 * 60 * 1000;
              }
              if (mapExt.Tag2 == 1 && mapExt.Tag3 != "") {
                var moment = require("moment");
                //let startTimestamp =Date.parse(new Date(_this.mainData[mapExt.Tag4]))*1;
                let startTimestamp =
                    moment(_this.mainData[mapExt.Tag4]).unix() * 1000;
                switch (mapExt.Tag3) {
                  case "dayu":
                    if (timestamp > startTimestamp) isTrue = false;
                    else isTrue = true;
                    break;
                  case "dayudengyu":
                    if (timestamp >= startTimestamp) isTrue = false;
                    else isTrue = true;
                    break;
                  case "xiaoyu":
                    if (timestamp < startTimestamp) isTrue = false;
                    else isTrue = true;
                    break;
                  case "xiaoyudengyu":
                    if (timestamp <= startTimestamp) isTrue = false;
                    else isTrue = true;
                    break;
                  case "budengyu":
                    if (timestamp == startTimestamp) isTrue = true;
                    else isTrue = false;
                    break;
                }
              }
            }
          });
          return isTrue;
        },
      };
    },

    WatchValue(mapAttr) {
      let val = "";
      let _this = this;
      let mapExts = mapAttr.MapExts;
      if (mapExts == undefined || mapExts.length == 0) return val;
      mapExts.forEach((mapExt) => {
        if (
            mapExt.ExtType == "AutoFull" &&
            mapExt.Doc != null &&
            mapExt.Doc != ""
        ) {
          if (testExpression(mapExt.Doc) == false) {
            this.$message.warning(
                "MyPk: " + mapExt.MyPK + ", 表达式: '" + mapExt.Doc + "'格式错误"
            );
            return true;
          }
          let doc = mapExt.Doc;
          for (var key in this.mainData) {
            doc = doc.replace(/'@'+key/g, this.mainData[key]);
            if (doc.indexOf("@") == -1) break;
          }
          _this.mainData[mapAttr.KeyOfEn] = eval(doc);
        }
      });
      return val;
    },
  },
  watch: {},
};
</script>

<style scoped>

.decode-form /deep/ .el-form-item__content {
  text-align: left;
}

.el-input {
  width: 100% !important;
}

.el-form-item {
  margin-bottom: 0 !important;
}
</style>

<style lang="scss" scoped>
.form-row {
  width: 100%;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: wrap;

  .form-item {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    min-height: 55px;
    line-height: 55px;
    height: auto;

    .form-item-label {
      flex-shrink: 0;
      font-size: 18px;
      font-weight: 300;
      text-align: left;
      box-sizing: border-box;
      padding-left: 12px;
      width: 100%;
    }
  }
}
</style>
